function getElement(arr, items) {
  Array.from(arr).forEach((item) => {
    if (item instanceof Array) {
      getElement(item, items)
    } else {
      items[items.length] = item
    }
  })
}

function Stack() {
  this.items = []

  // 1.压栈
  Stack.prototype.push = function() {
    getElement(arguments, this.items)
  }

  // 2.出栈
  Stack.prototype.pop = function() {
    let temp = this.items[this.items.length - 1]
    this.items.length--
      return temp
  }

  // 3.返回栈顶元素，不对栈做任何修改
  Stack.prototype.peek = function() {
    return this.items[this.items.length - 1]
  }

  // 4.判断栈空
  Stack.prototype.isEmpty = function() {
    return this.items.length === 0
  }

  // 5.返回栈里元素的个数
  Stack.prototype.size = function() {
    return this.items.length
  }

  // 5.将栈结构的内容以字符串的形式返回
  Stack.prototype.toString = function(punctuation) {
    return this.items.reverse().join(punctuation)
  }
}

module.exports = Stack

// let s = new Stack()

// s.push(1, 2, 3, [4, 5])
// console.log(s.items);